import * as vscode from 'vscode';
import { LoginService } from '../services/loginService';

export class StatusBar {
    private _statusBarItem: vscode.StatusBarItem;

    constructor(private context: vscode.ExtensionContext) {
        this._statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
        this._statusBarItem.show();
    }

    /**
     * 更新状态栏：调用loginService的isLoggedIn方法，如果已登录，则显示用户信息，否则显示登录按钮
     */
    public async update() {
        const loginService = LoginService.getInstance(this.context);
        const loggedIn = await loginService.isLoggedIn();
        if (loggedIn) {
            const userInfo = await loginService.getUserInfo();
            if (userInfo) {
                this._statusBarItem.text = `$(account) ${userInfo.cnName} - HarmonyPilot`;
                this._statusBarItem.tooltip = '已登录，点击可登出';
                this._statusBarItem.command = 'HarmonyPilot.logout';
            }
        } else {
            this._statusBarItem.text = '$(log-in) 登录 - HarmonyPilot';
            this._statusBarItem.tooltip = '点击可登录';
            this._statusBarItem.command = 'HarmonyPilot.login';
        }
    }

    /**
     * 释放状态栏
     */
    public dispose() {
        this._statusBarItem.dispose();
    }
} 